<?php
/**
 * Created by PhpStorm.
 * User: PGF(592472116@qq.com)
 * Date: 2016/8/22
 * Time: 10:48
 */

namespace Api\Controller;
use Think\Controller;
use Com\Message;
header("content-type:text/html;charset=utf-8");
class NotifyController extends Controller
{
	//--异步通知地址
	function index(){
		include APP_PATH.'../Alipay1/Alipay.class.php';
		$alipay = new \Alipay();
		$res = $alipay->verifyNotify();
		D('order')->pay($res);

        $order_no=$res['trade_no'];
        $order_id=M('order')->where(array('order_no'=>$order_no))->getField('id');
        if(!empty($order_id)){
            M('order_product')->where(array('order_id'=>$order_id))->save(array('create_time'=>time(),'update_time'=>time()));
            $productid_result=M('order_product')->field('product_id')->where(array('order_id'=>$order_id))->find();
            if (!empty($productid_result)){
                $userid_result=M('product')->field('uid')->where(array('id'=>$productid_result['product_id']))->find();
                if(!empty($userid_result)){
                    $phone_result=M('ucenter_member')->field('username')->where(array('id'=>$userid_result['uid']))->find();
                    $sales=M('product')->where(array('id'=>$productid_result['product_id']))->getField('sales');
                    M('product')->where(array('id'=>$productid_result['product_id']))->save(array('sales'=>intval($sales)+1));

                    Message::send($phone_result['username'],'尊敬的客户您好，您的门店收到了一笔新的订单，订单号为'.$order_no.'【战斗吧】');
                }
            }

        }
	}
}